package com.yzc.mihuyou.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.yzc.mihuyou.entity.Comment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yzc.mihuyou.entity.Invitation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 评论表 Mapper 接口
 * </p>
 *
 * @author 易紫诚
 * @since 2022-04-28
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {
    @Select("select * from \n" +
            "(select pinzan,count(*) as giveNum from\n" +
            "pingive group by pinzan) a, \n" +
            "(select * FROM comment) b  ${ew.customSqlSegment}")
    List<Comment> rower(@Param("page") IPage<Comment> page, @Param(Constants.WRAPPER) Wrapper<Comment> wrapper);

    @Select("SELECT C.user_id,C.blog_id,C.root_parent_id,C.comment_id,C.gmt_create,C.content,cs.content AS parent_Content FROM `comment` AS C\n" +
            "JOIN `comment` AS cs\n" +
            "ON C.parent_id = cs.comment_id\n" +
            "WHERE  cs.user_id = ${id}  and C.user_id <> ${id}  order by C.gmt_create DESC")
    List<Comment> getComment(long id);

}
